import Vue from 'vue'
import VueRouter from 'vue-router'
const _import = require('./_import')

Vue.use(VueRouter)

export const routers = [
	{
		path: '/',
		name: 'index',
		component: _import('home'),
		meta: {
			index: 0,			//页面顺序
			keepAlive: true, 	//需要被缓存
			isLogin: false		//是否需要路由拦截
		}
	},
	{
		path: '/about',
		name: 'about',
		component: _import('about'),
		meta: { index: 1} 
	},
	{
		path: '/main',
		name: 'main',
		component: _import('/main/index'),
		meta: { index: 1, keepAlive: false, isLogin: true }
	},
]


const routes = new VueRouter({
	routes: routers
});

//路由守卫
routes.beforeEach((to, from, next) => {
	let key = sessionStorage.getItem('key');
	if (to.meta.isLogin && !key) next({ name: 'about' })
	else next()
})
export default routes;
